﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ivy.Common.Framework.GeneralUtility
{
    public class AntiSpamUtility
    {
        #region Variables & Constants
        private string _MathFormula = string.Empty;
        private string _CorrectAnswer = string.Empty;
        #endregion Variables & Constants

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        #region Public Properties
        public string MathFormula
        {
            get
            {
                return _MathFormula;
            }
        }
        public string CorrectAnswer
        {
            get
            {
                return _CorrectAnswer;
            }
            set { _CorrectAnswer = value; }
        }
        #endregion Public Properties

        #region Public Methods
        public string GenerateMathFormula()
        {
            int FirstNumber = StringUtility.GenerateRandomNumber(1, 10);
            int SecondNumber = StringUtility.GenerateRandomNumber(1, 10, FirstNumber);
            int CalculationNum = 0;
            string MathOperator = StringUtility.GenerateRandomNumber(1, 4).ToString();
            switch (MathOperator)
            {
                case "1":
                    {
                        _MathFormula = FirstNumber.ToString() + " + " + SecondNumber.ToString();
                        CalculationNum = FirstNumber + SecondNumber;
                        break;
                    }
                case "2":
                    {
                        _MathFormula = FirstNumber.ToString() + " - " + SecondNumber.ToString();
                        CalculationNum = FirstNumber - SecondNumber;
                        break;
                    }
                case "3":
                    {
                        _MathFormula = FirstNumber.ToString() + " x " + SecondNumber.ToString();
                        CalculationNum = FirstNumber * SecondNumber;
                        break;
                    }
                case "4":
                    {
                        _MathFormula = FirstNumber.ToString() + " / " + SecondNumber.ToString() +" (provide only whole number)";
                        decimal DivResult = FirstNumber / SecondNumber;
                        CalculationNum = Convert.ToInt32(Math.Round(DivResult, 0));
                        break;
                    }
            }
            _CorrectAnswer = CalculationNum.ToString();
            //CorrectAnswer = CalculationNum.ToString();
            return _CorrectAnswer;
            //return CorrectAnswer;
        }
        public bool IsInputCorrect(string calcutatedAnswer)
        {
            bool IsCorrect = false;
            if (_CorrectAnswer == calcutatedAnswer)
            //if (CorrectAnswer == calcutatedAnswer)
            {
                IsCorrect = true;
            }
            return IsCorrect;
        }
        #endregion Public Methods

        #region Events
        #endregion Events

        #region Private Methods
        #endregion Private Methods
    }
}
